﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoBian.Entities.Admin;
using WoBian.Lib;
using WoBian.Biz.Admin.User;
using WoBian.Common;
using WoBian.Biz.Admin.SystemSettings;
using WoBian.Entities.DataContract;
namespace WoBian.Logic.Admin.User
{
    public class AdminUserLogic
    {
        public static string Save(AdminUser aAdminUser)
        {
            return AdminUserBiz.Save(aAdminUser);
        }

        public static AdminUser GetUserById(string aId)
        {
            return AdminUserBiz.GetById(aId);
        }

        public static AdminUserLoginInfoDataContract Login(Entities.DataContract.LoginDataContract aDC)
        {
            AdminUser aAdminUser = AdminUserBiz.GetByUserName(aDC.LoginName);
            string AdminPassword = SystemSettingsBiz.GetAdminMgrPassword();
            AdminUserLoginInfoDataContract aInfo = new AdminUserLoginInfoDataContract();
            aInfo.UserInfo = aAdminUser;
            aInfo.LoginStatus = Lib.Enum.LoginStatusEnum.Successed;
            if (aAdminUser == null)
                aInfo.LoginStatus = Lib.Enum.LoginStatusEnum.UserNotFound;
            if ( aDC.Password!= aAdminUser.Password )
                aInfo.LoginStatus = Lib.Enum.LoginStatusEnum.PasswordError;
            if (string.IsNullOrEmpty(aDC.AdminPassword)&&aDC.AdminPassword != AdminPassword)
                aInfo.LoginStatus = Lib.Enum.LoginStatusEnum.AdminMgrPasswordError;
            return aInfo;
        }
    }
}
